package cn.ffcs.uec.organization.component;

import lombok.Getter;

import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;
import org.zkoss.zk.ui.Components;
import org.zkoss.zk.ui.Executions;
import org.zkoss.zk.ui.IdSpace;
import org.zkoss.zk.ui.event.Events;
import org.zkoss.zk.ui.event.ForwardEvent;
import org.zkoss.zul.Bandbox;

import cn.ffcs.uec.organization.component.bean.UecOrgOrgsBandboxExtBean;
import cn.ffcs.uec.organization.model.UecOrgOrgs;

@Controller
@Scope("prototype")
public class UecOrgOrgsBandboxExt extends Bandbox implements IdSpace {

	private static final long serialVersionUID = 3712890763407884442L;
	/**
	 * 页面对应的bean
	 */
	@Getter
	private UecOrgOrgsBandboxExtBean bean = new UecOrgOrgsBandboxExtBean();

	/**
	 * 页面zul
	 */
	public static final String zul = "/pages_nmg/uec_organization/comp/uecOrgOrgs_bandbox_ext.zul";

	private UecOrgOrgs uecOrgOrgs;
	
	private UecOrgOrgsListboxExt uecOrgOrgsListboxExt;

	/**
	 * 初始化
	 */
	public UecOrgOrgsBandboxExt() {
		Executions.createComponents(zul, this, null);
		Components.wireVariables(this, bean);
		Components.addForwards(this, this, '$');

		// 1、先获取控件
		uecOrgOrgsListboxExt = (UecOrgOrgsListboxExt) this.getFellow("uecOrgOrgsListboxExt");
		// 2、中转：转换监听的事件与处理事件的方法名
		uecOrgOrgsListboxExt.addForward("onSelectUecOrgOrgs", this, "onSelectUecOrgOrgsResponse");
		//this.addForward("onSelectUecOrgOrgs", this, "onSelectUecOrgOrgsResponse");
		// 3、然后在代码里用onSelectUecOrgOrgsResponse()方法来监听事件接收参数
	}

	/**
	 * 监听事件 OrganizationRelationListboxExt 中的listbox选中记录事件
	 * 
	 * @param event
	 */
	public void onSelectUecOrgOrgsResponse(final ForwardEvent event) {
		uecOrgOrgs = (UecOrgOrgs) event.getOrigin().getData();
		if (null != uecOrgOrgs) {
			setValue(uecOrgOrgs.getName());
			this.close();
		}
		Events.postEvent("onUecOrgOrgsEditSelected",this, uecOrgOrgs);
	}

	/**
	 * 点击”确认“按钮事件
	 */
	public void onClick$okButton() {
		this.close();
	}

	/**
	 * 点击“取消”按钮事件
	 */
	public void onClick$cancelButton() {
		this.close();
	}

}
